Global_Banner_Info = function()
{
	this.path 		= '';
	this.width 		= '';
	this.height 	= '';
	this.url 		= '';
	this.hints 		= '';
	this.title 		= '';
	this.expired 	= 0 ;
	this.display 	= 0 ;
	this.is_hints 	= 0 ;
}
Global_Banner = function(info, id, varName)
{
	this.info		= info;
	this.id			= id;
	this.varName	= varName;
	this.arrImg 	= "jpg,jpeg,gif,png";
	this.arrSwf 	= "swf";
	this.adminView	= false;
	this.index		= 0;
	
	//Prototype
	this.show = function()
	{
		if (this.index==this.info.length)
		{
			this.index=0;
		}
		var oBannerInfo = this.info[this.index];
		if (oBannerInfo)
		{
			this.showBanner(oBannerInfo);
			if (oBannerInfo.is_hints==0)
			{
				this.getHints(oBannerInfo);
			}
		}
		this.index++;
	}
	
	this.showBanner = function(bannerInfo)
	{
		var curDate = new Date();
		if (this.adminView==false)
		{			
			if (bannerInfo.expired-curDate.getTime()<0)
			{
				document.getElementById(this.id).innerHTML = '';
				
				this.index++;
				this.show();
				return;
			}
		}
		var arrInfo = bannerInfo.path.split('.');
		var nLength = arrInfo.length;
		var ext = arrInfo[nLength-1].toLowerCase();
		if (this.arrImg.indexOf(ext)!=-1)
		{
			document.getElementById(this.id).innerHTML =  this.getImage(bannerInfo);
		}
		if (this.arrSwf.indexOf(ext)!=-1)
		{
			document.getElementById(this.id).innerHTML =  this.getFlash(bannerInfo);
		}
		if (this.adminView==false && this.info.length>1)
		{
			setTimeout(this.varName+'.show()',bannerInfo.display);
		}
		return null;
	}

	this.setAdminView = function()
	{
		this.adminView = true;
	}
	
	this.getImage = function(bannerInfo)
	{
		var html = '';
		html += '<a href="'+bannerInfo.url+'" style="cursor:pointer; float:none; width='+bannerInfo.width+'px; height='+bannerInfo.height+'px; z-index:99999;" target="_blank">';
		html += '<img src="'+bannerInfo.path+'" width="'+bannerInfo.width+'" heigth="'+bannerInfo.height+'" title="'+bannerInfo.title+'" border="0" />';
		html += '</a>';
		return html;
	}
	
	this.getFlash = function(bannerInfo)
	{
		var html = '';
		html += '<a href="'+bannerInfo.url+'" style="cursor:pointer; float:left; width='+bannerInfo.width+'px; height='+bannerInfo.height+'px; z-index:99999;" target="_blank">';
		html += '<embed width="'+bannerInfo.width+'" height="'+bannerInfo.height+'" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" quality="high" bgcolor="#FFFFFF" src="'+bannerInfo.path+'" type="application/x-shockwave-flash"/>';
		html += '</a>';
		return html;
	}
	
	this.shuffle = function()
	{
		for(var j, x, i = this.info.length; i; j = parseInt(Math.random() * i), x = this.info[--i], this.info[i] = this.info[j], this.info[j] = x);
		return this.info;
	}
	
	this.getHints = function(bannerInfo)
	{
		var oHttpRequest = this.createHttpRequest();
		if (oHttpRequest && bannerInfo.hints)
		{
			oHttpRequest.onreadystatechange = function(){};
			oHttpRequest.open("GET", bannerInfo.hints, true);
			oHttpRequest.send(null);
		}
		bannerInfo.is_hints = 1;
	}
	
	this.createHttpRequest = function()
	{
		if (typeof XMLHttpRequest!="undefined")
		{
			return new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			var arrVersion = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
			var n = arrVersion.length;
			for(i=0; i<n; i++)
			{
				try
				{
					vrequest = new ActiveXObject(arrVersion[i]);
					return vrequest;
				}
				catch(objErr){}
			}
			return null;
		}
	}
}